******************************************************************************************************
* Replication BJPS: Understanding Voter Fatigue: Election Frequency \& Electoral Abstention Approval *
******************************************************************************************************

*** Define the path that leads to the replication files 

*global beg_path `"C:\Users\XXX\Replication files\"' 

*** Installing user-written commands 

ssc install fre 
net install grc1leg, from(http://www.stata.com/users/vwiggins/) 
  
*** Uploading the dataset  

use `"${beg_path}Kostelka_BJPS_Dataset.dta"', clear


*** Generating the DV

gen approval = V31_1 
replace approval = V31_2 if approval ==. 
replace approval = V31_3 if approval ==. 
replace approval = V31_4 if approval ==. 
replace approval = V31_5 if approval ==. 


*** Generating Groups by Experimental Condition

gen group_1 = V31_1 !=.
lab var group_1 "Control"
gen group_2 = V31_2 !=. 
lab var group_2 "Presidential"
gen group_3 = V31_3 !=. 
lab var group_3 "Municipal"
gen group_4 = V31_4 !=. 
lab var group_4 "European"
gen group_5 = V31_5 !=. 
lab var group_5 "Three Elections"

egen group_type = group(group_5 group_4 group_3 group_2 group_1) // important to order the var in the descending order (so that group1 = 1 etc.)
label define group_type 1 "Control" 2 "Presidential" 3"Municipal" 4"European" 5"Three Elections"
label value group_type group_type

gen group_6 = group_type > 1
lab var group_6 "Any Treatment" 

gen group_7 = group_6 & group_5!=1
replace group_7 = 0 if group_5 
lab var group_7 "One Election"


*** Generating a dummy for passing the manipulation test 

gen Manip_test = 0
replace Manip_test = 1 if V32_1 == 1 & group_1==1 & V32_2==1
replace Manip_test = 1 if V32_1 == 2 & (group_2==1 | group_3==1 | group_4==1) & V32_2==1
replace Manip_test = 1 if V32_1 == 3 & group_5==1 & V32_2==1

*** Controls 

*Gender 
tab V2, gen(gender)
label define Gender 3 "Other Gender", modify

*Education
label define Education 2 "Vocational Education" 3 "High School Education" 4 "University Education", modify

*Income 
fre V68
  
*Age
fre V3

*Political interest
fre V11 

*Duty 
fre V40
gen duty = V40*(-1)+10 // Reversing the coding of the variable

*Participation in the last legislative elections 
recode V14 (5=1) (else=0), gen(parl_vote) // DK is considered as abstention
lab var parl_vote "Participation (last election)"

*Religion 
fre V63 V64
recode V63 (1/4 = 1) (else=0), gen(temp1)
gen christian = temp1 ==1 & V64<4
lab var christian "Observing Christian" 

***************
*** Results ***
***************

*** Setting the folder for results  
cd `"${beg_path}Replication_results"'

*** Figure 1 

cap frame drop results
cap frame create results double(group b lb ub) // Create frame for results 

mean approval, over(group_6) // Control vs. any treatment
frame post results (7) (r(table)[1,1]) (r(table)[5,1]) (r(table)[6,1]) 
frame post results (6) (r(table)[1,2]) (r(table)[5,2]) (r(table)[6,2]) 

mean approval, over(group_type) // Control vs. different treatments 
frame post results (4) (r(table)[1,2]) (r(table)[5,2]) (r(table)[6,2]) 
frame post results (3) (r(table)[1,3]) (r(table)[5,3]) (r(table)[6,3]) 
frame post results (2) (r(table)[1,4]) (r(table)[5,4]) (r(table)[6,4]) 
frame post results (1) (r(table)[1,5]) (r(table)[5,5]) (r(table)[6,5]) 

mean approval, over(group_7) // Control vs. one election
frame post results (5) (r(table)[1,2]) (r(table)[5,2]) (r(table)[6,2]) 

set scheme stgcolor
frame results: tw scatter group b, mc(black) mlabel(b) mlabp(1) mlabf(%9.2f) mlabc(black) || rcap lb ub group , horizontal lc(black)  ///
  xlabel(4(.1)5, grid) xline(4.48, lc(red)) legend(off) ///
 ylabel(7 "Control" 6 "Any Treatment" 5 "One Election" 4 "Presidential"  3 "Municipal" 2 "European" 1 "Three Elections") ytitle("") xtitle("")

// For the manuscript 
 graph export "Figure_1.eps", replace  // width(3000) 

/* For presentations 
frame results: tw scatter group b if _n <3, mc(black) mlabel(b) mlabp(1) mlabf(%9.2f) mlabc(black) || rcap lb ub group if _n <3, horizontal lc(black)  ///
  xlabel(4.2(.1)4.8, grid) xline(4.48, lc(red)) legend(off) ///
 ylabel(7 "Control" 6 "Any Treatment") yscale(r(5 8)) ytitle("") xtitle("")
graph export "Figure_1a.eps", replace  //  */
  

// For the interpretation of stat significance 
ttest approval , by(group_1) // Any, p = 0.0025
ttest approval if group_1 == 1 | group_2 == 1, by(group_1) // Presidential, p = 0.07
ttest approval if group_1 == 1 | group_3 == 1, by(group_1) // Municipal, p = 0.3271
ttest approval if group_1 == 1 | group_4 == 1, by(group_1) // European, p = 0.0245
ttest approval if group_1 == 1 | group_5 == 1, by(group_1) // Three, p = 0.0000
ttest approval if group_1 == 1 | group_7 == 1, by(group_1) // Three, p = 0.0378

frame drop results // we no longer need these results 


*** Table 1
eststo clear
eststo M1: reg approval group_6  
estadd local fixed "No" , replace  
eststo M2: areg approval group_6, absorb(Country)
estadd local fixed "Yes" , replace 
eststo M3: areg approval group_2 group_3 group_4 group_5, absorb(Country)
test group_2 = group_3 // p = 0.3453
test group_3 = group_4 // p = 0.1626
estadd local fixed "Yes" , replace 
eststo M4: areg approval group_5 group_7, absorb(Country)
estadd local fixed "Yes" , replace 
eststo M5: areg approval group_6 if Manip_test == 1, absorb(Country)
estadd local fixed "Yes" , replace 

esttab M1 M2  M3 M4 M5 using Table_1.tex, one incelldelimite("\:")  stats(fixed N r2, labels("Country FE"  "N" "R2") ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 0 3)) ///
		replace b(2) se(2) wide staraux ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none)  /// drop(*.Country)
		label nobase nodep nolegend note("") alignment(d{10}) order(group_6 group_7 group_2 group_3 group_4 group_5) /// 
		mtitles("All respondents" "All respondents" "All respondents" "All respondents"  "Passed m. check")

		
*** Figure 2		
		
*Re-estimation of model 4 without "3 elections (not to have the same coefficient twice - both from M3 and M4)
eststo M4: areg approval group_7 if group_5==0, absorb(Country)
	
		coefplot M2 M4 M3 , drop(_cons) mlabel mlabp(1) mc(black) mlabf(%9.2f) mlabc(black) legend(off) ciopts(lcol(black)) ///
		xline(0, lc(red) lpattern(dash)) ylabel(1 "Any treatment" 2 "One Election" 3 "Presidential"  4 "Municipal" 5 "European" 6 "Three elections") xlabel(-.5(.1).5, grid) xline(0, lc(red))
 	
 graph export "Figure_2.eps", replace  // width(3000) 

				
/*Additional tests and figures for presentations  

coefplot M2 M3, drop(_cons) mlabel mlabp(1) mc(black) mlabf(%9.2f) mlabc(black) legend(off) ciopts(lcol(black))  ///
ylabel(1 "Any treatment" 2 "Presidential"  3 "Municipal" 4 "European" 5 "Three elections") xlabel(-.5(.1).5, grid) xline(0, lc(red))
 		

eststo M3: areg approval group_7 group_5, absorb(Country)
test group_7 = group_5
eststo M3: areg approval i.group_5 if group_7==1 | group_5==1, absorb(Country)
margins, dydx(group_5)
marginsplot, plot1opts(mc(black) lc(black)) ci1opts(lcol(black)) title("") xlabel(1 "Difference: Three Elections vs. One Election") ylabel(-.5(.1).5) ///
ytitle("Abstention Approval") yline(0, lc(red)) ysize(2) xsize(2) 
graph export "Figure_1b.eps", replace  // width(3000) */		
		
		
*** Table 2
eststo clear
eststo M1: areg approval i.group_6 duty, absorb(Country)
estadd local fixed "Yes" , replace  
eststo M2: areg approval i.group_6##c.duty, absorb(Country) 
estadd local fixed "Yes" , replace  
eststo M3: areg approval i.group_6 c.V11, absorb(Country) 
estadd local fixed "Yes" , replace 
eststo M4: areg approval i.group_6##c.V11, absorb(Country) 
estadd local fixed "Yes" , replace 

esttab M1 M2 M3 M4 using Table_2.tex, one incelldelimite("\:")  stats(fixed N r2, labels("Country FE"  "N" "R2") ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 0 3)) ///
		replace b(2) se(2) wide staraux ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none) ///  drop(*.Country)
		 nobase nodep nolegend note("") alignment(d{10}) /// 
		nomtitles varlabels(1.group_6 "Any" 1.group_6#c.V11 "Any X Interest" V11 "Interest" 1.group_6#c.duty "Any X Duty" duty "Duty" _cons "Constant")

*** Figure 3 		
		
areg approval i.group_6##c.duty, absorb(Country) 
 margins group_6, at(duty=(0(1)10))
 marginsplot, name(g1, replace) title("Duty", nospan) xtitle("Duty to vote") ytitle("Abstention Approval") legend(order(3 "Control" 4 "Treatment (Any)") r(1) pos(6)) ///
 plot1opts(mc(black) lc(black)) ci1opts(lcol(black)) plot2opts(mc(gray*0.6) lc(gray*0.6)) ci2opts(lcol(gray*0.6))

		
 areg approval i.group_6##c.V11, absorb(Country) 	
 margins group_6, at(V11=(0(1)10))
 marginsplot, name(g2, replace) title("Interest", nospan)  xlabel(0 "0" 1 2 3 4 5 6 7 8 9 10 "10") xtitle("Interest in Politics") ytitle("Abstention Approval") legend(order(3 "Control" 4 "Treatment (Any)") r(1) pos(6)) ///
plot1opts(mc(black) lc(black)) ci1opts(lcol(black)) plot2opts(mc(gray*0.6) lc(gray*0.6)) ci2opts(lcol(gray*0.6))

 graph combine g1 g2
 grc1leg g1 g2 
 graph export "Figure_3.eps", replace  
 
 
*** Appendix Table 1
 
* Generating Dummies  
tab V2, gen(dum_V2)
tab V3, gen(dum_V3) 
tab V68, gen(dum_V68)
tab V5, gen(dum_V5)
tab Country, gen(dum_country)

* Polishing labels  
labvarch dum_V2* dum_V3* dum_V68* dum_country* dum_V5*, after(==)  
lab define group_type 1 "Control" 2 "Presid." 3 "Municip." 4 "EP" 5 "3 Elec.", replace
lab values group_type group_type
lab var group_type "Treatment Group"

* Getting a local macro with the variables 
local vars dum_V2* dum_V3* dum_V5* dum_V68* parl_vote dum_country* group_type // group_1 group_2 group_3 group_4 group_5


/* For the next table, the results folder has to include two files: top.tex and bot.tex

The content of top.tex:

\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabularx}{\linewidth}{@{} l *{6}{>{\centering\arraybackslash}X} @{}}
\toprule

The content of bot.tex:

\bottomrule
\end{tabularx}

*/


* Getting the table 
cap tabout `vars' using Table_A1test.tex, c(col) f(1) bt replace style(tex) topf(top.tex) botf(bot.tex) topstr(10cm)  /// topf(top.tex) botf(bot.tex) are files 
cl1(2-7) ptotal(none)



*** Appendix Table 2 (balance tests)

eststo clear
eststo M0: reg group_1 i.V2 i.V3 i.V5 i.V68 i.Country
eststo M1: reg group_1 i.V2 i.V3 i.V5 i.V68 i.Country if group_1==1 | group_2==1 
eststo M2: reg group_1 i.V2 i.V3 i.V5 i.V68 i.Country if group_1==1 | group_3==1 
eststo M3: reg group_1 i.V2 i.V3 i.V5 i.V68 i.Country if group_1==1 | group_4==1 
eststo M4: reg group_1 i.V2 i.V3 i.V5 i.V68 i.Country if group_1==1 | group_5==1 

esttab M0 M1 M2 M3 M4 using Table_A2.tex, one incelldelimite("\:")  stats(N r2, labels( "N" "R2") /// fixed "Country FE" 
		layout( "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 3)) /// "\multicolumn{1}{c}{@}"
		replace b(2) se(2) wide staraux ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none) /// 
		label nobase nodep nolegend note("") alignment(d{10}) /// 
		mtitles("Control vs Any" "Control vs Presidential" "Control vs Municipal" "Control vs European" "Control vs Three Elections")

*** Appendix Table 3 (analysis with controls) & by country 

eststo clear  
eststo M1: reg approval group_6 if Country!=1, absorb(Country) // CZ 
estadd local fixed "Yes" , replace  
eststo M2: reg approval group_6 if Country!=2, absorb(Country) // FR
estadd local fixed "Yes" , replace  
eststo M3: reg approval group_6 if Country!=3, absorb(Country) // PL
estadd local fixed "Yes" , replace  
eststo M4: reg approval group_6 if Country!=4, absorb(Country) // RO
estadd local fixed "Yes" , replace  
eststo M5: reg approval group_6 if Country!=5, absorb(Country) // SK
estadd local fixed "Yes" , replace  		
eststo M6: reg approval group_6 i.V2 i.V3 i.V5 i.V68 , absorb(Country) 
estadd local fixed "Yes" , replace 

esttab M1 M2 M3 M4 M5 M6 using Table_A3.tex, one incelldelimite("\:")  stats(fixed N r2, labels("Country FE"  "N" "R2") ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 0 3)) ///
		replace b(2) se(2) wide staraux ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none) /// 
		label nobase nodep nolegend note("") alignment(d{10}) /// 
		mtitles("Without CZ" "Without FR" "Without PL" "Without RO" "Without SK" "With Controls" )

*** Appendix Figure 1 (distribution of the DV) 

hist approval, frac by(group_type, row(2) note("") ) xsize(5) ysize(2) xtitle("Approval")  color(black)
graph export "Figure_A1.eps", replace   

*** Appendix Table 4 (addressing extreme response bias) 
recode approval (0/4=0) (5=0.5) (6/10=1), gen(approval_binary)

eststo clear  
eststo M1: reg approval group_6 if approval!=0 & approval!=10 & approval!=5, absorb(Country) 
estadd local fixed "Yes" , replace  
eststo M2: reg approval_binary group_6 if approval_binary!=0.5, absorb(Country) 
estadd local fixed "Yes" , replace  
eststo M3: ologit approval group_6 i.Country	
estadd local fixed "Yes" , replace  
estadd scalar r2 = e(r2_p)		

esttab M1 M2 M3  using Table_A4.tex, one incelldelimite("\:")  stats(fixed N r2, labels("Country FE"  "N" "R2") ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 0 3)) ///
		replace b(2) se(2) wide staraux drop(*.Country) ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none) /// 
		label nobase nodep nolegend note("") alignment(d{10}) /// 
		mtitles("Without 0, 5, 10" "Binary Coding" "Ordered Logit" )
		
*** Appendix Figure 2
teffects psmatch (approval) (group_6 i.V2 i.V3 i.V68  i.Country)
matrix list r(table)
frame create new estimate b lb ub
frame post new (1) (r(table)[1,1]) (r(table)[5,1]) (r(table)[6,1])
teffects psmatch (approval) (group_6 i.V2 i.V3 i.V68 i.Country) if Manip_test==1
frame post new (2) (r(table)[1,1]) (r(table)[5,1]) (r(table)[6,1])

frame new: tw scatter b estimate , mc(black) mlabel(b) mlabp(1) mlabf(%9.2f) mlabc(black) || rcap lb ub estimate, lc(black)  /// 
xlabel(1 "ATE (all respondents)" 2 "ATE (passed manip. check)") yline(0, lc(red)) legend(off) ///
 xscale(r(0.5 2.5)) ytitle("")  ylabel(-.5(.1).5) xtitle("")
graph export "Figure_A2.eps", replace    
 

*** Appendix Table 5

eststo clear
eststo M1: areg approval i.group_6##ib1.dum_V22 if V2!=3, absorb(Country) 
estadd local fixed "Yes" , replace 
eststo M2: areg approval i.group_6##i.dum_V35, absorb(Country) 
estadd local fixed "Yes" , replace 
eststo M3: areg approval i.group_6##i.dum_V54, absorb(Country) 
estadd local fixed "Yes" , replace 
eststo M4: areg approval i.group_6##ib1.parl_vote, absorb(Country) 
estadd local fixed "Yes" , replace 
eststo M5: areg approval i.group_6##i.christian, absorb(Country) 
estadd local fixed "Yes" , replace 

areg approval i.group_6 if V64>4, absorb(Country)

esttab M1 M2 M3 M4 M5 using Table_A5.tex, one incelldelimite("\:")  stats(fixed N r2, labels("Country FE"  "N" "R2") ///
		layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  fmt(0 0 3)) ///
		replace b(2) se(2) wide staraux ///
		star(# 0.1 * 0.05 ** 0.01 *** 0.001) eqlabels(none) ///  drop(*.Country)
		 nobase nodep nolegend note("") alignment(d{10}) /// 
		nomtitles varlabels(1.group_6 "Any" 1.group_6#0.dum_V22 "Any X Male" 0.dum_V22 "Male" ///
		1.group_6#1.dum_V35 "Any X University Education" 1.dum_V35 "University Education" ///
		1.group_6#1.dum_V54 "Any X 65 years and more" 1.dum_V54 "65 years and more" ///
		1.group_6#0.parl_vote "Any X Abstained"  0.parl_vote "Abstained" ///
		1.group_6#1.christian "Any X Observ. Christian" 1.christian "Observ. Christian")
		 




 